package lee.meiriyiti.day1117;

import java.util.Scanner;
//https://www.nowcoder.com/questionTerminal/fe298c55694f4ed39e256170ff2c205f
//汽水瓶
public class TestDemo1117_1 {

    public static int change(int n) {
        int total = 0;
        while (n > 2) {
            total = total + n / 3;//第一次可以换n/3瓶
            n = n / 3 + n % 3;//剩下的瓶子等于第一次换到的+不够换的
        }
        if (n == 2) {//当等于两个时，可以借一个
            total = total + 1;
        }
        return total;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            if (n == 0) break;
            else {
                System.out.println(change(n));
            }
        }
    }
}
